package com.zhn.evsi.controller.Industry;

import cn.hutool.core.util.ObjectUtil;
import com.zhn.evsi.common.Result;
import com.zhn.evsi.domain.dto.evsi.EvsiIndustryActivityMaterialsDTO;
import com.zhn.evsi.domain.dto.evsi.EvsiPlanetSelectDTO;
import com.zhn.evsi.domain.dto.evsi.EvsiPlanetTreeDTO;
import com.zhn.evsi.domain.entity.evsi.EvsiInvtypes;
import com.zhn.evsi.domain.entity.evsi.EvsiMarketgroups;
import com.zhn.evsi.exception.CustomException;
import com.zhn.evsi.service.IEvsiIndustryActivityMaterialsService;
import com.zhn.evsi.service.IEvsiMarketgroupsService;
import com.zhn.evsi.service.IEvsiPlanetSchematicsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "工业制造")
@RestController
@RequestMapping("Evsi/industry")
public class EvsiIndustryController {

    @Autowired
    private IEvsiIndustryActivityMaterialsService industryActivityMaterialsService;

    @Autowired
    private IEvsiPlanetSchematicsService planetSchematicsService;

    @Autowired
    private IEvsiMarketgroupsService marketgroupsService;


    /**
     * 工业制造
     * */
    // 蓝图制造
    @ApiOperation("蓝图制造信息")
    @GetMapping("/bluePrint")
    public Result bluePrint(@RequestParam(defaultValue = "") Integer typeId,
                            @RequestParam(defaultValue = "") Integer quantity) {
        EvsiIndustryActivityMaterialsDTO evsiIndustryActivityMaterialsDTO = industryActivityMaterialsService.bluePrint(typeId, quantity);
        return Result.success(evsiIndustryActivityMaterialsDTO);
    }

    @ApiOperation("递归获取planeTypeId(树状结构)")
    @GetMapping("/selectBluePrint")
    public Result selectBluePrint () {
        List<EvsiMarketgroups> evsiMarketgroups = marketgroupsService.groupsMenu(2);
        return Result.success(evsiMarketgroups);
    }

    @ApiOperation("递归获取planeTypeId(树状结构)二级分层查询")
    @GetMapping("/groupsBluePrint")
    private Result groupsBluePrint(@RequestParam Integer marketGroupId) {
        List<EvsiInvtypes> evsiInvtypes = marketgroupsService.groupsType(marketGroupId);
        return Result.success(evsiInvtypes);
    }

    /**
     * 行星开发
     * */
    // 行星产物树状结构
    @ApiOperation("行星产物树状结构")
    @GetMapping("/planetTree")
    public Result planetTree(@RequestParam(defaultValue = "") Integer schematicID,
                             @RequestParam(defaultValue = "") Integer quantity) {
        if (schematicID == null) {
            throw new CustomException("服务错误！");
        }
        if (ObjectUtil.isNull(quantity)) {
            quantity = 1;
        }
        EvsiPlanetTreeDTO evsipPlanetTreeDTO = planetSchematicsService.planetTree(schematicID, quantity);
        return Result.success(evsipPlanetTreeDTO);
    }

    // 行星产物下拉选择
    @ApiOperation("行星产物下拉选择")
    @GetMapping("/planetSelect")
    public Result planeSelect(@RequestParam(defaultValue = "") String level) {
        List<EvsiPlanetSelectDTO> evsiPlanetSelectDTOS = planetSchematicsService.planetSelect(level);
        return Result.success(evsiPlanetSelectDTOS);
    }
}
